<template>
  <div class="content-wrap content-container" v-loading="loading">
    <!-- 快速搜索 -->
    <div class="card-table-search">
      <el-button :type="activeButton === 1 ? 'primary' : 'info'" @click="getAllRequirementsBtn(1)">
        <span>全部：</span>
        <span style="color: #cca409;">{{ statusCounts.length1 }}</span>
      </el-button>
      <el-button :type="activeButton === 2 ? 'primary' : 'info'" @click="getAllRequirementsBtn(2)">
        <span>自己：</span>
        <span style="color: #cca409;">{{ statusCounts.length2 }}</span>
      </el-button>
    </div>
    <el-table :data="allRequirements" style="width: 100%; overflow-y: auto; "
      height="750" border stripe>
      <el-table-column fixed type="index" label="序号" width="60" align="center"></el-table-column>
      <el-table-column prop="requirementName" label="需求名称">
        <template #="{ row }">
          <p class="table-requirement-name" @click="handleRowClick(row.id)">{{ row.requirementName }}</p>
        </template>
      </el-table-column>
      <el-table-column prop="requirementManagerName" label="项目经理" align="center" width="140">
        <template #="{ row }">
          <span>{{ row.requirementManagerName }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="requirementRelevances" label="研发" align="center" width="140">
        <template #="{ row }">
          <span>{{ row.requirementRelevances }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="contactTestNames" label="测试" align="center" width="140">
        <template #="{ row }">
          <span>{{ row.contactTestNames }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="requirementLinuxs" label="运维" align="center" width="140">
        <template #="{ row }">
          <span>{{ row.requirementLinuxs }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="requirementBossName" label="技术负责人" align="center" width="140">
        <template #="{ row }">
          <span>{{ row.requirementBossName }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="guessTime17" label="上线时间" align="center" width="140">
        <template #="{ row }">
          <span>{{ tableTimeDateMsg(row.guessTime17) }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="requirementSecurityName" label="保障人" align="center" width="140">
        <template #="{ row }">
          <span>{{ row.requirementSecurityName }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="requirementSecurityIphone" label="保障人手机号" align="center" width="140">
        <template #="{ row }">
          <span>{{ row.requirementSecurityIphone }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="操作" width="120" align="center">
        <template #default="{row}">
          <el-button type="primary" plain size="small" @click="handleRowEvaluate(row.itemRequirementChilds)" :disabled="row.itemRequirementChilds.length == 0">评价</el-button>
        </template>
      </el-table-column> -->
    </el-table>


    <!-- 需求详情弹窗 -->
    <el-dialog style="width: 1200px;" :close-on-click-modal="false" v-model="dialogInfoVisible"
      @close="dialogInfoVisible = false" @closed="dialogInfoVisible = false" top="8vh">
      <CommonRequirementInfoVue :isRequirementID="isRequirementID" :clearData="clearData" :isComment="true">
      </CommonRequirementInfoVue>
    </el-dialog>
  </div>
</template>

<script setup lang='ts'>
import { ref, onMounted, reactive } from 'vue'
import { GetThisDayOnlineRequirement } from "@/api/newDemands/index";
import { ElMessage } from 'element-plus';
import CommonRequirementInfoVue from "@/components/requirement/comomRequirementInfo.vue";
import { tableTimeDateMsg } from '@/utils/utils';

const loading = ref(false);
const isRequirementID = ref<any>(null); //当前操作任务ID
const dialogInfoVisible = ref(false);//查看需求弹窗控件
const clearData = ref(false);//控制是否清空子组件数据
const allRequirements = ref<any>([]);// 项目经理所有未评价需求
const activeButton = ref(2); // 默认激活第一个按钮
const statusCounts = reactive({
  length1: 0,
  length2: 0,
});

// TODO 获取项目经理未评价需求
const getAllRequirements1 = async () => {
  loading.value = true;
  const { data } = await GetThisDayOnlineRequirement({
    isAll: 1
  });
  if (data.code === 200 && data.data !== null) {
    allRequirements.value = data.data;
    console.log("获取数据：", allRequirements.value.length);
    statusCounts.length1 = allRequirements.value.length
  } else if (data.code === 200 && data.data == null) {
    ElMessage.warning("暂无数据");
    loading.value = false;
    return;
  } else {
    ElMessage.error(data.msg);
    loading.value = false;
    throw console.error(data.msg);
  };

  loading.value = false;
};
const getAllRequirements2 = async () => {
  loading.value = true;
  const { data } = await GetThisDayOnlineRequirement({
    isAll: 2
  });
  if (data.code === 200 && data.data !== null) {
    allRequirements.value = data.data;
    statusCounts.length2 = allRequirements.value.length
  } else if (data.code === 200 && data.data == null) {
    ElMessage.warning("暂无数据");
    loading.value = false;
    return;
  } else {
    ElMessage.error(data.msg);
    loading.value = false;
    throw console.error(data.msg);
  };

  loading.value = false;
};


const getAllRequirementsBtn = async (id: number) => {
  loading.value = true;
  activeButton.value = id
  const { data } = await GetThisDayOnlineRequirement({
    isAll: id
  });
  if (data.code === 200 && data.data !== null) {
    allRequirements.value = data.data;
    ElMessage.success(data.msg);
  } else if (data.code === 200 && data.data == null) {
    ElMessage.warning("暂无数据");
    loading.value = false;
    return;
  } else {
    ElMessage.error(data.msg);
    loading.value = false;
    throw console.error(data.msg);
  };

  loading.value = false;
}


// TODO 查看需求
const handleRowClick = async (id: number) => {
  isRequirementID.value = id;
  dialogInfoVisible.value = true;
};

onMounted(() => {
  getAllRequirements1();
  getAllRequirements2();
});
</script>
<style lang='scss' scoped>
.content-container {
  display: flex;
  flex-direction: column;

  .table-requirement-name:hover {
    color: #409EFF;
    cursor: pointer;
  }

  .dialog-form-footer {
    width: 100%;
    text-align: right;
  }
}
.card-table-search {
  margin-bottom: 10px;
}
</style>
